#include "Capsule.h"
#include "ShareComponents.h"
#include "Camera.h"
#include "Box.h"
#include "Sprite.h"
#include "MainGame.h"
#include "GunWeapon.h"
#include "RSManager.h"
Capsule::Capsule(Box* box, SPRITE_ID gunWeapon_id) : Object(box, ObjEnemy_DYNAMID)
{
	_initpos=box->_position;
	_gunWeapon_id= gunWeapon_id;
}
void Capsule::init()
{
	_isActive=false;
	_sprite = RSManager::getInstance()->getSprite(CAPSULES);
	_hits=1;
	_isAlive=true;
	AssignMove(_box);
}
void Capsule :: update()
{
	if(gl_camera->getLeftSide()>_initpos.x+_box->_size.x){
		_isActive =true;
		moveSinY(8);
		if(_hits<=0|| _box->_position.x>gl_camera->getRightSide()) {
			_isAlive=false;
		}
		if(_hits<=0){
			GunWeapon* gunWeapon=new GunWeapon
				(new Box(_box->_position,D3DXVECTOR2(48,30),D3DXVECTOR2(5,0)),_gunWeapon_id);
			gunWeapon->init();
			gl_MainGame->addWorldObject(gunWeapon);
		}
	}
	
}
void Capsule::render()
{
	if(_isAlive && _isActive)
	_sprite->Render(_box->_position);
}
Box* Capsule::getCollisionBox()
{
	_colBox->_position = _box->_position;
	_colBox->_size = _box->_size;
	_colBox->_v = _box->_v;
	return _colBox;
}
Capsule::~Capsule(void)
{
}
